home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / copyobj / newobj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  3.0 KB  |  132 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <libraries/dos.h>
  4. #include <workbench/workbench.h>
  5. #include <workbench/startup.h>
  6.  
  7. #include <clib/alib_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/dos_protos.h>
  10. #include <clib/icon_protos.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. struct Library *IconBase=NULL;
  15. void sr(char *s);
  16.  
  17. char source[200];
  18. char destination[200];
  19. char itype[200];
  20. UBYTE tooltype[40][80];
  21. char toolfilename[200];
  22. void InitTypes(char *s);
  23.  UBYTE *tools[40];
  24.  
  25. main(int argc,char *argv[])
  26. {
  27.   char *s;
  28.   int i;
  29.   UBYTE mytype;
  30.   struct DiskObject *src;
  31.   struct DiskObject *dst;
  32.   struct Gadget *srcgad;
  33.   struct DiskObject new;
  34.   BOOL success=FALSE;
  35.   for(i=0;i<39;i++)
  36.      tools[i]=&tooltype[i];
  37.   if(argc!=5)
  38.   {
  39.      printf("NewObj version 1.0, written by Joseph Hodge\n");
  40.      printf("usage: NewObj <source.info> <destination.info> <type> [toolfilename]\n");
  41.      printf("   ie: NewObj Serial.info BBS:Node1/Serial.info DRAWER RAM:tools\n");
  42.      printf("\n");
  43.      printf("types: DISK\n");
  44.      printf("       DRAWER\n");
  45.      printf("       TOOL\n");
  46.      printf("       PROJECT\n");
  47.      printf("\n\n");
  48.      exit(0);
  49.   }
  50.   strcpy(source,argv[1]);
  51.   strcpy(destination,argv[2]);
  52.   sr(source);
  53.   sr(destination);
  54.   strcpy(itype,argv[3]);
  55.   sr(itype);
  56.   mytype=WBTOOL;
  57.   if(!strnicmp(itype,"DRAWER",6)) mytype=WBDRAWER;
  58.   if(!strnicmp(itype,"DISK",4)) mytype=WBDISK;
  59.   if(!strnicmp(itype,"TOOL",4)) mytype=WBTOOL;
  60.   if(!strnicmp(itype,"PROJECT",7)) mytype=WBPROJECT;
  61.  
  62.   strcpy(toolfilename,argv[4]);
  63.   sr(toolfilename);
  64.   InitTypes(toolfilename);
  65.   i=strlen(source)-1;
  66.   while(i>=0)
  67.   {
  68.      if(source[i]=='.') break;
  69.      i--;
  70.   }
  71.   if(i) source[i]='\0';
  72. i=strlen(destination)-1;
  73.   while(i>=0)
  74.   {
  75.      if(destination[i]=='.') break;
  76.      i--;
  77.   }
  78.   if(i) destination[i]='\0';
  79.  
  80.   IconBase=OpenLibrary("icon.library",0L);
  81.   if(src=GetDiskObject(source))
  82.   {
  83.  
  84.     srcgad=(struct Gadget *)&src->do_Gadget;
  85.        CopyMem(src,&new,sizeof(struct DiskObject));
  86.        new.do_Gadget.Width=srcgad->Width;
  87.        new.do_Gadget.Height=srcgad->Height;
  88.        new.do_Gadget.Flags=srcgad->Flags;
  89.        new.do_Gadget.Activation=srcgad->Activation;
  90.        new.do_Gadget.GadgetType=srcgad->GadgetType;
  91.        new.do_Gadget.GadgetRender=srcgad->GadgetRender;
  92.        new.do_Gadget.SelectRender=srcgad->SelectRender;
  93.        InitTypes(toolfilename);
  94.        new.do_ToolTypes=(APTR)tools;
  95.        new.do_Type= mytype;
  96.        new.do_CurrentX=NO_ICON_POSITION;
  97.        new.do_CurrentY=NO_ICON_POSITION;
  98.        PutDiskObject(destination,(struct DiskObject *)&new);
  99.     FreeDiskObject(src);
  100.   }
  101.   CloseLibrary(IconBase);
  102.   exit(0);
  103. }
  104. void InitTypes(char *s)
  105. {
  106.    FILE *fi;
  107.    register int i=0;
  108.    int j=0;
  109.    char image[100];
  110.    fi=fopen(s,"r");
  111.    if(fi!=NULL)
  112.    {
  113.      while(fgets(image,80,fi)!=NULL && i<39)
  114.      {
  115.         sr(image); strcpy(&tooltype[i][0],image);
  116.         i++;
  117.      }
  118.      fclose(fi);
  119.    }
  120.    tools[i]=NULL;
  121. }
  122. void sr(char *s)
  123. {
  124.    register int i;
  125.    i=strlen(s)-1;
  126.    while(i>-1)
  127.    {
  128.      if(*(s+i)<=32) *(s+i)='\0'; else break;
  129.      i--;
  130.    }
  131. }
  132.